<!DOCTYPE HTML>
<html>
<head>
    {include file="common:meta"}
</head>
<body>
<div class="page-container">
    <div class="ibox-content" id="toolbar">
        <form action="" class="form-inline" id="form" data-url="">
            <div class="form-group">
                <label class="control-label" for="key">请选择:</label>
                <select id="key" class="form-control" name="key">
                    <option value="u_id">ID</option>
                    <option value="nickname">族长名称</option>
                    <option value="f_name">预审家族名称</option>
                </select>
            </div>

            <div class="form-group">
                <label class="control-label" for="value">输入:</label>
                <input class="form-control" id="value" type="text" name="value">
            </div>
            <button type="button" class="btn btn-primary" id="eventQuery">查询</button>
            <button type="button" onclick="location.replace(location.href);" class="btn btn-success ">刷新</button>
        </form>
    </div>
    <div class=" float-e-margins">
        <div class="ibox-content">
            <div class="tabs-container">
                <ul class="nav nav-tabs">
                    <li class="active"><a data-toggle="tab" href="#tab-1" aria-expanded="true">家族列表</a>
                    </li>
                </ul>
                <div class="tab-content">
                    <div class=" tab-pane active" id="tab-1">
                        <table id="tb_departments"></table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
{include file="common:footer"}
<script>
    $(document).ready(function () {
        initTable();
    });

    function initTable() {
        $('#tb_departments').bootstrapTable({
            url: '/CheckFamilyListIndexData',         //请求后台的URL（*）
            dataField: "data",
            method: 'get',                      //请求方式（*）
            striped: true,                      //是否显示行间隔色
            cache: true,                       //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）
            pagination: true,                   //是否显示分页（*）
            queryParams: queryParams,//传递参数（*）
            showToggle: true,
            showRefresh: true,
            sidePagination: "server",           //分页方式：client客户端分页，server服务端分页（*）
            pageNumber: 1,                       //初始化加载第一页，默认第一页
            pageSize: 10,                       //每页的记录行数（*）
            pageList: [10, 25, 50, 100],        //可供选择的每页的行数（*）
            showColumns: true,                  //是否显示所有的列
            showPaginationSwitch: true,
            minimumCountColumns: 2,             //最少允许的列数
            toolbar: '#toolbar',
            columns: [{
                field: 'id',
                title: 'ID',
                sortable: true
            },{
                field: 'u_id',
                title: '族长ID'
            },{
                field: 'nickname',
                title: '族长名称'
            },{
                field: 'f_name',
                title: '预审家族名称',
            },{
                field: 'r_id',
                title: '预审流水厅ID'
            },{
                field: 'r_name',
                title: '预审流水厅名'
            },{
                field: 'num',
                title: '家族人数',
            },{
                field: 'check_num',
                title: '预审周期人数'
            },{
                field: 'recheck_num',
                title: '复审周期人数',
            },{
                field: 'status',
                title: '状态',
                formatter: function (value, row, index) {

                    var arr = [];
                    arr[1] = '审核中';
                    arr[2] = '复审';
                    arr[3] = '已通过';
                    arr[4] = '已解散';
                    return arr[row.status] ? arr[row.status] : '未知状态';
                }
            },{
                field: 'create_time',
                title: '创建时间'
            },{
                field: 'Button',
                title: '操作',
                events: operateEvents,
                formatter: operateFormatter
            }],
            //保存的使用
            onEditableSave: function (field, row, oldValue, $el) {
                //可进行异步操作
                $.ajax({
                    type: "post",
                    url: "/AliEdit",
                    data: row,
                    dataType: 'JSON',
                    success: function (re) {
                        if (re.code === 1) {
                            layer.msg(re.msg, {icon: 1, time: 2000});
                        } else {
                            layer.alert(re.msg);
                        }
                    },
                    error: function () {
                        alert('编辑失败');
                    },
                    complete: function () {

                    }

                });
            }
        });
    }

    //得到查询的参数

    function queryParams(params) {
        params.offset = params.offset / params.limit + 1;
        params.key = $('#key').val();
        params.value = $('#value').val();
        return params;
    }
    function operateFormatter(value, row, index){

        if(row.status===1 || row.status===2) var agree_sho = 'inline-block';
        else var agree_sho = 'none';

        if(row.status === 1 && row.recheck_status === 1) var review_sho = 'inline-block';
        else var review_sho = 'none';

        return [
            '<button type="button"  class="family-member btn btn-primary  btn-sm" style="margin-right:15px;">查看家族成员</button>',
            '<button type="button"  class="flowing-info btn btn-w-m btn-primary  btn-sm" style="margin-right:15px;">查看房间流水</button>',
            '<button type="button"  class="family-liveness btn btn-w-m btn-primary  btn-sm" style="margin-right:15px;">查看活跃度</button>',
            '<button type="button"  class="agree btn btn-w-m btn-danger  btn-sm" style="margin-right:15px; display: '+ agree_sho+';">通过</button>',
            '<button type="button"  class="review btn btn-w-m btn-danger  btn-sm" style="margin-right:15px;display: '+ review_sho+';">复审</button>',
            '<button type="button"  class="dismiss btn btn-w-m btn-danger  btn-sm" style="margin-right:15px; display: '+ agree_sho+';">解散</button>'
        ].join('');
    }

    window.operateEvents = {
        'click .family-member': function (e, value, row, index) {
            layer.open({
                type: 2,
                title: ['家族成员','font-size:18px;font-family:宋体;font-weight:700;'],
                shadeClose: true,
                shade: false,
                maxmin: true, //开启最大化最小化按钮
                area: ['1000px', '600px'],
                content:"/FamilyMemberInfo?family_id=" + row.family_id + '&user_id=' + row.user_id,
                offset:'auto',
                scrollbar:false
            });
        },
        'click .flowing-info':function(e,value,row,index){
            layer.open({
                type: 2,
                title: ['房间流水信息','font-size:18px;font-family:宋体;font-weight:700;'],
                shadeClose: true,
                shade: false,
                maxmin: true, //开启最大化最小化按钮
                area: ['1000px', '600px'],
                content:"/RoomFlowingInfo?roomId=" + row.id,
                offset:'auto',
                scrollbar:false
            });
        },
        'click .family-liveness':function(e,value,row,index){
            layer.open({
                type: 2,
                title: ['预审家族活跃度信息','font-size:18px;font-family:宋体;font-weight:700;'],
                shadeClose: true,
                shade: false,
                maxmin: true, //开启最大化最小化按钮
                area: ['1000px', '600px'],
                content:"/FamilyActiveInfo?familyId=" + row.family_id,
                offset:'auto',
                scrollbar:false
            });
        },
        //同意
        'click .agree':function(e,value,row,index){
            $.ajax({
                type: "get",
                url: "/CheckFamilyAgree",
                data: {
                    id:row.id
                },
                dataType: 'JSON',
                success: function (re) {
                    if (re.code === 100) {
                        layer.msg(re.msg, {icon: 1, time: 2000});
                        $('#tb_departments').bootstrapTable(('refresh'));	// 很重要的一步，刷新url！
                    } else {
                        layer.msg(re.msg, {icon: 2, time: 2000});
                    }
                },
                error: function () {
                    layer.msg('操作失败');
                }
            });
        },
        //复审
        'click .review':function(e,value,row,index){
            $.ajax({
                type: "get",
                url: "/CheckFamilyReview",
                data: {
                    id:row.id
                },
                dataType: 'JSON',
                success: function (re) {
                    if (re.code === 100) {
                        layer.msg(re.msg, {icon: 1, time: 2000});
                        $('#tb_departments').bootstrapTable(('refresh'));	// 很重要的一步，刷新url！
                    } else {
                        layer.msg(re.msg, {icon: 2, time: 2000});
                    }
                },
                error: function () {
                    layer.msg('操作失败');
                }
            });
        },
        //解散
        'click .dismiss':function(e,value,row,index){
            $.ajax({
                type: "get",
                url: "/CheckFamilyDismiss",
                data: {
                    id:row.id
                },
                dataType: 'JSON',
                success: function (re) {
                    if (re.code === 100) {
                        layer.msg(re.msg, {icon: 1, time: 2000});
                        $('#tb_departments').bootstrapTable(('refresh'));	// 很重要的一步，刷新url！
                    } else {
                        layer.msg(re.msg, {icon: 2, time: 2000});
                    }
                },
                error: function () {
                    layer.msg('操作失败');
                }
            });
        }
    };
    // 搜索按钮触发事件
    $(function () {
        $("#eventQuery").click(function () {
            $('#tb_departments').bootstrapTable(('refresh'));	// 很重要的一步，刷新url！
        });

    });
</script>
</body>
</html>